/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package events.pose;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import javax.swing.JTextField;
import snazzysprites.SnazzySprites;
import state.SnazzySpritesStateManager;

/**
 * Handles the change of the current pose's duration in the current animation.
 * @author Andrew Gratta <andrew.gratta@stonybrook.edu>
 */
public class ChangePoseDurationHandler implements FocusListener {

    @Override
    public void focusGained(FocusEvent e) {
        
    }

    @Override
    public void focusLost(FocusEvent e) {
        SnazzySprites singleton = SnazzySprites.getSnazzySprites();
        SnazzySpritesStateManager manager = singleton.getStateManager();
        JTextField textField = (JTextField)e.getSource();
        String newDurationString = textField.getText();
        
        if (newDurationString == null)
        {
            textField.setText(manager.getPose().getDuration() + "");
            return;
        }
        
        int newDuration = Integer.parseInt(newDurationString);
        
        if (newDuration < 1 || newDuration > 100)
        {
            textField.setText(manager.getPose().getDuration() + "");
            return;
        }
        
        manager.getPose().setPoseDuration(newDuration);
    }

    
    
}
